from openai import OpenAI


class ChatGLM_LLM:
    def __init__(self, config):

        self.model_name = config.get("model_name")
        self.api_key = config.get("api_key")
        self.url = config.get("url")
        self.client = OpenAI(api_key=self.api_key, base_url=self.url)

    def response(self, dialogue):
        responses = self.client.chat.completions.create(
            model=self.model_name,
            messages=[{"role": "user", "content": dialogue}],
            stream=False
        )
        return responses.choices[0].message.content